package com.chzu.service.Impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.chzu.mapper.SysPermissionMapper;
import com.chzu.pojo.SysPermission;
import com.chzu.result.JsonResult;
import com.chzu.result.PageResult;
import com.chzu.result.QueryInfo;
import com.chzu.service.SysPermissionService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author lz
 * @Version 1.0
 * @Company 滁州大健康与养老产业研究院
 * @ClassName SysPermissionImpl
 * @Description TODO
 * @Date 2022/01/27 15:13
 */
@Service
public class SysPermissionImpl extends ServiceImpl<SysPermissionMapper, SysPermission> implements SysPermissionService {

    @Resource
    private SysPermissionMapper permissionMapper;

    /**
     *  分页插叙你
     * @param queryInfo 页码、大小、查询内容
     * @return
     */
    @Override
    public JsonResult<Object> findPermission(QueryInfo queryInfo) {
        PageHelper.startPage(queryInfo.getPageNumber(), queryInfo.getPageSize());
        Page<SysPermission> page = permissionMapper.findPermission(queryInfo.getQueryString());
        long total = page.getTotal();
        List<SysPermission> result = page.getResult();
        return PageResult.pageResult(result, total);
    }

    /**
     *  添加权限信息
     * @param permission 权限信息
     * @return
     */
    @Override
    public JsonResult<Object> insertPermission(SysPermission permission) {
        permissionMapper.insertPermission(permission);
        return JsonResult.ok("添加权限信息成功");
    }

    /**
     *
     * @param id
     * @return 权限id
     */
    @Override
    public JsonResult<Object> deletePermission(Integer id) {
        permissionMapper.deletePermission(id);
        return JsonResult.ok("删除权限信息成功");
    }

    /**
     *  修改权限信息
     * @param permission 权限信息
     * @return
     */
    @Override
    public JsonResult<Object> updatePermission(SysPermission permission) {
        permissionMapper.updatePermission(permission);
        return JsonResult.ok("修改权限信息成功");
    }

    /**
     * 查询所有的权限数据
     * @return
     */
    @Override
    public JsonResult<Object> findAllPermission() {
        return JsonResult.ok(permissionMapper.findAllPermission());
    }
}
